<template>
  <elm-page-tb style="max-height: calc(100% - 40px)" :splite="false" :splite-show="false">
    <template #top>
      <el-form label-width="80px" ref="post" :model="postData" size="small">
        <elm-row>
          <el-form-item label="项目名称">
            <el-input placeholder="请输入查询内容" prefix-icon='el-icon-search' v-model="postData.name" clearable></el-input>
          </el-form-item>
          <el-form-item label="项目类型">
            <elm-select-tree v-model="postData.type" url="/business/my/business/GetPjTree" path-url="/business/my/business/GetPjPath"></elm-select-tree>
          </el-form-item>
          <el-form-item label="所属部门">
            <elm-org v-model="postData.org"></elm-org>
          </el-form-item>
          <el-form-item label="项目经理">
            <elm-ei v-model="postData.manager"></elm-ei>
          </el-form-item>
        </elm-row>
      </el-form>
      <right>
        <el-button-group style="margin-top: 10px">
          <el-button icon="el-icon-search" size="mini" @click="tablebinding()">查询</el-button>
          <elm-open-button url="pj_edit" icon="el-icon-edit" title="新增" width="900" height="90%" :data="{pid: '0', pname: '无' }">新增</elm-open-button>
        </el-button-group>
      </right>
    </template>
    <elm-table url="/business/my/business/GetPjByUser" :post-data="postData" :default-expand-all="true" :page-size="50" height="100%">
      <el-table-column prop="sys_code_key" label="项目编号" align="center" width="120px">
      </el-table-column>
      <el-table-column prop="name" label="名称" align="center" width="250px">
      </el-table-column>
      <el-table-column prop="type_mc" label="项目类型" align="center" min-width="120px">
      </el-table-column>
      <el-table-column prop="money" label="项目资金(万元)" header-align="center" align="right"  width="120px">
      </el-table-column>
      <el-table-column prop="org_mc" label="所属部门" align="center" width="160px">
      </el-table-column>
      <el-table-column prop="manager_mc" label="项目经理" align="center" width="80px">
      </el-table-column>
      <el-table-column prop="b_sdate" label="开工日期" align="center" width="100px">
      </el-table-column>
      <el-table-column prop="contract_key" label="合同编号" align="center" width="120px">
      </el-table-column>
      <el-table-column prop="a_org" label="委托单位" header-align="center"  width="250px">
      </el-table-column>
      <el-table-column fixed="right" label="进度" width="150px" align="center">
        <template v-slot="scope">
          <div style="display: inline-block;width: 80px;margin-right:10px;">
            <el-progress :text-inside="true" :stroke-width="16" :percentage="scope.row.progress"
                         :color="scope.row.progress<50?'#f56c6c':'#6f7ad3'" text-color="#fff"></el-progress>
          </div>
          <elm-open-button url="pj_stage" title="进度维护" width="1000" height="90%"
                           :data="{ pj_id:scope.row.id, sys_code_key: scope.row.sys_code_key, progress:scope.row.progress, b_edate:scope.row.b_edate }"
                           type="text" v-if="scope.row.manager==now_user">维护</elm-open-button>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="工作" width="60px" align="center" >
        <template v-slot="scope">
          <elm-open-button url="pj_task" title="工作分解" width="1000" height="90%" :data="{ pj_id: scope.row.id,is_manager: scope.row.manager==now_user }" type="text">分解</elm-open-button>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100px" align="center"  style="position:absolute">
        <template v-slot="scope">
          <elm-open-button url="pj_edit" title="编辑" width="900" height="90%" :data="{ model: scope.row }" type="text" v-if="scope.row.manager==now_user">编辑</elm-open-button>
          <elm-open-button url="pj_edit" title="查看" width="900" height="90%" :data="{ model: scope.row , disable:true }" type="text" v-if="scope.row.manager!=now_user">查看</elm-open-button>
          <el-button type="text" size="mini" @click="deleteData(scope.row)" v-if="scope.row.manager==now_user">删除</el-button>
        </template>
      </el-table-column>
    </elm-table>
  </elm-page-tb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData: { name: null },
      now_user:null
    }
  },
  async created() {
    this.now_user=await this.get_user_ei();
  },
  methods: {
    async deleteData(data) {
      await this.delete('/business/my/business/DeletePj', { id: data.id });
      this.tablebinding();
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>

<style scoped>
</style>